from src.application.category.dto import CategoryDTO
from src.application.category.uow import CategoryUoW
from src.application.category.use_cases.filter_categories import FilterCategories, FilterCategoriesHandler
from src.application.category.use_cases.get_category_by_id import GetCategoryById, GetCategoryByIdHandler
from src.application.category.use_cases.get_category_by_name import GetCategoryByName, GetCategoryByNameHandler
from src.application.category.use_cases.get_category_for_private import (
    GetCategoryForPrivate,
    GetCategoryForPrivateHandler,
)


class CategoryService:
    def __init__(
        self,
        *,
        uow: CategoryUoW,
    ) -> None:
        self._uow = uow

    async def get_category_by_id(self, category_id: int, joined: bool = False) -> CategoryDTO:
        """Получаем категорию по id"""

        command = GetCategoryById(category_id)
        return await GetCategoryByIdHandler(uow=self._uow)(command=command)

    async def get_category_by_name(self, category_name: str) -> CategoryDTO:
        """Получаем категорию по имени"""

        command = GetCategoryByName(category_name)
        return await GetCategoryByNameHandler(uow=self._uow)(command=command)

    async def get_category_for_private(self, country_id: int, provider_id: int) -> CategoryDTO:
        """Получаем категорию для приватных прокси"""

        command = GetCategoryForPrivate(country_id=country_id, provider_id=provider_id)
        return await GetCategoryForPrivateHandler(uow=self._uow)(command=command)

    async def filter_categories(self, query: FilterCategories):
        """Фильтруем категории"""

        return await FilterCategoriesHandler(uow=self._uow)(query=query)
